package gui;

import processing.core.PApplet;

public class Point {

	private int id;
	private int posX;
	private int posY;
	private int color;
	
	private boolean selected;
	private boolean highlighted;
	private boolean changed;
	private int current;
	
	private static final int STAND_BY = 0;
	private static final int SELECTED = 1;
	private static final int HIGHLIGHTED = 2;

	
	public static final int SIZE = 5;
	
	private PApplet mainApplet;
	
	public Point()
	{
		selected = false;
		highlighted = false;
		current = STAND_BY;
		changed = false;
	}
	
	public Point(int id, int posX, int posY, int color, PApplet mainApplet)
	{
		this.id = id;
		this.posX = posX;
		this.posY = posY;
		this.color = color;
		this.mainApplet = mainApplet;
	}
	
	public int getId() {
		return id;
	}

	public boolean overPoint (){
		float disX = posX - mainApplet.mouseX;
		float disY = posY - mainApplet.mouseY;

		if(PApplet.sqrt(PApplet.sq(disX) + PApplet.sq(disY)) < SIZE) {
			return true;
		}else{
			return false;
		}
	}
	
	public void setSelected()
	{
		if(current != SELECTED)
		{
			current = SELECTED;
			changed = true;
			selected = true;
		}
		else
		{
			changed = false;
		}
	}
	
	public void setUnselected()
	{
		if(selected)
		{
			changed = true;
			selected = false;
		}
		else
		{
			changed = false;
		}
	}
	
	public boolean isSelected()
	{
		return selected;
	}
	
	public void setHiglighted()
	{
		if(current != HIGHLIGHTED)
		{
			highlighted = true;
			changed = true;
			current = HIGHLIGHTED;
		}
		else
		{
			changed = false;
		}
	}
	
	public void setUnhighlighted()
	{
		highlighted = false;
	}
	
	public boolean drawPoint()
	{
		int pointSize = SIZE;
		changed = true;
		if(changed)
		{
			mainApplet.stroke(color);
			if(selected)
			{
				mainApplet.fill(color);
				pointSize *= 2;
			}
			else if(highlighted)
			{
				mainApplet.fill(color);
			}
			else
			{
				mainApplet.noFill();
			}
			mainApplet.ellipse (posX, posY, pointSize, pointSize);
		}
		return changed;
	}

	public int getPosX() {
		return posX;
	}

	public int getPosY() {
		return posY;
	}

	public void setColor(int currentColor) {
		color = currentColor;
	}
	
	
}
